package behavioralPatterns.state;

interface State {
    void doAction(Context context);
}

class Context {
    private State state;

    public Context(State state) {
        this.state = state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public State getState() {
        return state;
    }

    public void request() {
        state.doAction(this);
    }
}

class StartState implements State {
    public void doAction(Context context) {
        System.out.println("Player is in start state");
        context.setState(this);
    }

    public String toString() {
        return "Start State";
    }
}

class StopState implements State {
    public void doAction(Context context) {
        System.out.println("Player is in stop state");
        context.setState(this);
    }

    public String toString() {
        return "Stop State";
    }
}

public class StatePattern {
    public static void main(String[] args) {
        StartState startState = new StartState();
        StopState stopState = new StopState();

        Context context = new Context(startState);
        context.request();

        context.setState(stopState);
        context.request();
    }
}
